package cn.boc;

import cn.boc.factory.FruitStore;
import cn.boc.factory.SimpleFruitFactory;
import cn.boc.pojo.Fruit;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

/**
 * @description: 水果选择演示demo
 */
public class Demo {
    public static void main(String[] args) {

        SimpleFruitFactory simpleFruitFactory = new SimpleFruitFactory();
        FruitStore fruitStore = new FruitStore(simpleFruitFactory);
        Scanner scanner = new Scanner(System.in);
        ArrayList<Fruit> fruits = new ArrayList<Fruit>();
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("apple","apple");
        map.put("banada","banada");
        map.put("pear","pear");
        map.put("orange","orange");
        System.out.println("此为优惠专区，必须选择3个水果方可购买！");
        System.out.println("温馨提示：购买水果后，请放入小篮中...");
        while (true){

           System.out.println("您有一下几种选择：apple、banana、pear、orange");
           System.out.println("请选择您想购买的水果:");
           String str = scanner.nextLine();
           if(map.containsKey(str)){Fruit fruit = fruitStore.orderFruit(str);
               fruits.add(fruit);
               if(fruits.size()>2){
                   System.out.println("您的篮子满了!");
                   break;
               }
           }else{
               System.out.println("商店不存在该水果！请重新选择！");
           }
       }
    }

}

